1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>demo</title> </head> <body> <?php // 连接数据库 $server = '127.0.0.1:3306'; $username = 'sun'; $password = '7e63de77'; $database_mysql = 'mksql';
$sqlconn = mysqli_connect($server,$username,$password,$database_mysql); if (!$sqlconn) { echo "数据库连接失败"; }
// 查询数据库 $sqlcomm = "SELECT id,name,age FROM user"; $res = mysqli_query($sqlconn,$sqlcomm); // 输出数据库 if (mysqli_num_rows($res)>0) { while ($row = mysqli_fetch_assoc($res)) { echo "当前用户ID:".$row["id"]." -用户名称:".$row["name"]."用户注册年限:".$row["age"]; } } else { echo "当前数据表中暂无数据"; } // 关闭数据库流 mysqli_close($sqlconn); ?> </body> </html>
|